<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" isELIgnored="false" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
</head>
<body>
<form>
    <table>
        <tr>
            <td>姓名：</td>
            <td>
                <input id="name" type="text" name="uname" class="textSize">
            </td>
        </tr>
        <tr>
            <td>密码：</td>
            <td>
                <input id="pwd" type="password" name="upwd" class="textsize">
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <input type="button" onclick="goLog()" value="登录">
                <input onclick="window.history.go(-1)" type="button" value="取消">
                <span id="errorMsg"></span>
            </td>
        </tr>
    </table>
</form>
<script type="text/javascript">
    function goLog() {
        // 获取文本框的值
        const username = $("#name").val();
        const pwd = $("#pwd").val();
        $.ajax({
            url: "${pageContext.request.contextPath}/my/testRequest",
            type: "POST",
            data: {"uname": username, "upwd": pwd},
            success: function (data) {
                if (data === "ok") {
                    //登录成功
                    window.location.href = "http://www.baidu.com/";
                } else {
                    //失败
                    $("#errorMsg").css("color", "red").html("错误");
                }
            }
        });
    }
</script>
</body>
</html>